package Start;

import Registrationsystem.Department;

import java.util.ArrayList;
import java.util.Scanner;

public class HospitalManager {
    private Scanner sc = new Scanner(System.in);
    private ArrayList<Department> alldepartment = new ArrayList<>();
    //开始方法
    public void Start(){
        while (true) {
            System.out.println("=====挂号管理系统====");
            System.out.println("请选择您想要办理的业务类型");
            System.out.println("1.科室管理");
            System.out.println("2.医生管理");
            System.out.println("3.挂号");
            System.out.println("4.查询");
            int command = sc.nextInt();
            switch (command){
                case 1:
                    DepartmentManager();
                    break;
                case 2:
                    DockerManager();
                    break;
                case 3:
                    break;
                case 4:
                    break;
                default:
                    System.out.println("您输入的命令有误，请重新输入~");
            }
        }
    }
    //科室管理方法
    public void DepartmentManager(){
        while (true) {
            System.out.println("====欢迎进入科室管理系统====");
            System.out.println("请选择要业务类型");
            System.out.println("1.增加科室");
            System.out.println("2.修改科室");
            System.out.println("3.删除科室");
            System.out.println("4.退出");
            int command = sc.nextInt();
            switch (command){
                case 1:
                    AddDepartment();
                    break;
                case 2:
                    ChangeDepartmentName();
                    break;
                case 3:
                    DeleDepartment();
                    break;
                case 4:
                    return;
                default:
                    System.out.println("您输入的命令有误，请重新输入~");
            }
        }
    }
    //医生管理系统
    public void DockerManager(){
        while (true) {
            System.out.println("====欢迎进入医生管理====");
            System.out.println("请选择操作类型");
            System.out.println("1.增加医生");
            System.out.println("2.查看医生排版情况");
            System.out.println("3.退出");
            int command = sc.nextInt();
            switch (command){
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    return;
                default:
                    System.out.println("您输入的命令有误，请重新输入~");
            }
        }
    }
    //增加科室
    public void AddDepartment() {
        System.out.println("===增加科室===");
        String name = null;
        OUT:
        while (true) {
            System.out.println("请输入科室名称");
            name = sc.next();
            for (int i = 0; i < alldepartment.size(); i++) {
                Department Departent = alldepartment.get(i);
                if (Departent.getDepartmentName().equals(name)) {
                    System.out.println("您输入的科室已存在~");
                    continue OUT;
                }
            }
            Department department = new Department();
            department.setDepartmentName(name);
            alldepartment.add(department);
            System.out.println("恭喜您，添加成功！");
            break;
        }
    }
    //修改科室名称方法
    public void ChangeDepartmentName(){
        String newname = "";
        System.out.println("===修改科室名称===");
        //展示当前所有科室，用户根据编号选择要修改的科室名称
        for (int i = 0; i < alldepartment.size(); i++) {
            Department name = alldepartment.get(i);
            System.out.println(i+1 +"."+ name.getDepartmentName());
    }
        System.out.println("请选择想要修改的科室编号");
        int command = sc.nextInt();
        Department changename = alldepartment.get(command-1);
        OUT:
        while (true) {
            System.out.println("您想要修改的名称是");
            newname = sc.next();
            for (int j = 0; j < alldepartment.size(); j++) {
                Department department = alldepartment.get(j);
                if (department.getDepartmentName().equals(newname)){
                    System.out.println("您输入的科室已存在，请重新输入");
                    continue OUT;
                }else
                    changename.setDepartmentName(newname);
                System.out.println("恭喜您修改成功");
                return;
            }
        }
    }
    //删除科室
    public void DeleDepartment(){
        //首先展示所有科室 用户选择想要删除的科室
        System.out.println("===删除科室===");
        for (int i = 0; i < alldepartment.size(); i++) {
            Department name = alldepartment.get(i);
            System.out.println(i+1 +"."+ name.getDepartmentName());
        }
        while (true) {
            System.out.println("请选择您想要删除的科室");
            int command = sc.nextInt();
            Department department = alldepartment.get(command - 1);
            if (department.getDockers().isEmpty()){
                alldepartment.remove(command - 1);
                System.out.println("恭喜您删除成功~~~~");
                return;
            }else {
                System.out.println("该科室内仍有医生，无法删除");
            }
        }
    }
}
